#ifndef DDEDOCKINTERFACE_H
#define DDEDOCKINTERFACE_H


#include <QtDBus/QtDBus>

/*
 * Proxy class for interface com.deepin.dde.DockFrontEnd
 */
class DBusDockInterface: public QDBusAbstractInterface
{
    Q_OBJECT

    Q_SLOT void __propertyChanged__(const QDBusMessage& msg)
    {
        QList<QVariant> arguments = msg.arguments();
        if (3 != arguments.count())
            return;
        QString interfaceName = msg.arguments().at(0).toString();
        if (interfaceName != "com.deepin.dde.Dock")
            return;
        QVariantMap changedProps = qdbus_cast<QVariantMap>(arguments.at(1).value<QDBusArgument>());
        foreach(const QString &prop, changedProps.keys()) {
            const QMetaObject* self = metaObject();
            for (int i=self->propertyOffset(); i < self->propertyCount(); ++i) {
                QMetaProperty p = self->property(i);
                if (p.name() == prop) {
                    emit p.notifySignal().invoke(this);
                }
            }
        }
    }
public:
    static inline const char *staticInterfaceName()
    { return "com.deepin.dde.Dock"; }

public:
    DBusDockInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0)
        : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
    {
        QDBusConnection::sessionBus().connect(this->service(), this->path(), "org.freedesktop.DBus.Properties",  "PropertiesChanged","sa{sv}as", this, SLOT(__propertyChanged__(QDBusMessage)));
    }

    ~DBusDockInterface()
    {
        QDBusConnection::sessionBus().disconnect(service(), path(), "org.freedesktop.DBus.Properties",  "PropertiesChanged",  "sa{sv}as", this, SLOT(propertyChanged(QDBusMessage)));
    }

    Q_PROPERTY(QRect geometry READ geometry NOTIFY GeometryChanged)
    inline QRect geometry() const
    { return qvariant_cast< QRect >(property("geometry")); }

    inline QDBusPendingReply<QRect> geometry_async()
    {
        QList<QVariant> argumentList;
        return asyncCallWithArgumentList(QLatin1String("geometry"), argumentList);
    }

    Q_PROPERTY(qint32 uid READ uid)
    inline QDBusPendingReply<qint32> uid()
    {
        QList<QVariant> argumentList;
        return asyncCall(QLatin1String("uid"),argumentList);
    }

//    inline QDBusPendingReply<uint> RequestName(const QString &in0, uint in1)
//    {
//        QList<QVariant> argumentList;
//        argumentList << QVariant::fromValue(in0) << QVariant::fromValue(in1);
//        return asyncCallWithArgumentList(QLatin1String("RequestName"), argumentList);
//    }

public Q_SLOTS: // METHODS
Q_SIGNALS: // SIGNALS
    void geometryChanged(const QRect &geometry);
    // begin property changed signals
    void GeometryChanged();
};


#endif // DDEDOCKINTERFACE_H
